package com.base.binarytree;

import java.util.Stack;

public class InvertTree {
    public TreeNode invertTree(TreeNode root) {
        if (root == null) {
            return null;
        }

        invert(root);
        return root;
    }

    public void invert(TreeNode root) {
        if (root.left == null) {
            root.left = root.right;
            root.right = null;
            return;
        }
        if (root.right == null) {
            root.right = root.left;
            root.left = null;
            return;
        }

        TreeNode tmp = root.left;
        root.left =root.right;
        root.right = tmp;


    }


}
